fix: incorrect canonical
and alternative
URL annotations
#2159
+18
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check List
Summary
There is a problem with the
canonical
andalternative
URL annotations in the<head>
tag of the page where the translation exists.This is probably why when we search for "hexo" on Google, we get strange results in some languages.
This pull request provides corrections to errors and improvements in
<head>
, with the aim of displaying search results as naturally as possible.Current
<head>
tagFor example, https://hexo.io/zh-tw/api/ outputs the following (excerpt):
For this example:
canonical
tag does not properly indicate a canonical URL because thepretty_urls.trailing_index: false
setting means the URL should end with '/'.alternative
is incorrect. The correct term isalternate
.alternate
tag incorrectly points to URLs with duplicate:lang
slugs, leading to either nonexistent URLs or URLs that incorrectly display content in English despite indicating a different language.alternative
again points to the URL for the language being displayed (zh-tw
in this example).There is a problem as above. In the screenshot at the beginning, it seems that Google is unable to recognize the correspondence between pages in each language, and this is probably the cause.
Fixes and improvements with this pull request
canonical
tag mentioned above. Omitindex.html
at the end.alternative
toalternate
above.alternate
above.alternate
does not output the displayed URL itself.alternative
is output in/:lang/about/
but the page does not exist. Delete this.As a result of these modifications, the URL annotation will look like this (excerpt):
Reference